import Vue from 'vue'
import Router from 'vue-router'
import storejs from 'store'
import STORECONST from '../common/storeConst'
import store from '@/store'
import {PAGELOADING} from '@/store/mutation-types'
// import {Loading} from 'vue-ydui/dist/lib.rem/dialog'

const HomeIndex = r => require.ensure([], () => r(require('@/pages/HomeIndex/HomeIndex')), 'HomeIndex')
// 配置懒加载 分块 路由 参考:https://router.vuejs.org/zh-cn/advanced/lazy-loading.html
const MyInfo = r => require.ensure([], () => r(require('@/pages/my/MyInfo')), 'MyInfo')
const Home = r => require.ensure([], () => r(require('@/pages/home/Home')), 'Home')
const Login = r => require.ensure([], () => r(require('@/pages/my/Login')), 'Login')
const appLogin = r => require.ensure([], () => r(require('@/pages/login/appLogin')), 'appLogin')
const form = r => require.ensure([], () => r(require('@/pages/form/form')), 'form')
const Register = r => require.ensure([], () => r(require('@/pages/login/Register')), 'Register')
// 我的主页
const My = r => require.ensure([], () => r(require('@/pages/my/MyIndex')), 'MyIndex')
// 用户信息
const UserInfo = r => require.ensure([], () => r(require('@/pages/my/UserInfo')), 'UserInfo')
// 修改密码
const Updatepswd = r => require.ensure([], () => r(require('@/pages/my/Updatepswd')), 'Updatepswd')
// 改绑手机
const UpdatePhoneNum = r => require.ensure([], () => r(require('@/pages/my/UpdatePhoneNum')), 'UpdatePhoneNum')
// 我的卡
const MyCard = r => require.ensure([], () => r(require('@/pages/my/MyCard')), 'MyCard')
const Retrievepassword = r => require.ensure([], () => r(require('@/pages/login/Retrievepassword')), 'Retrievepassword')
// demo start
const demo = r => require.ensure([], () => r(require('@/pages/demo')), 'demo')
const querytab = r => require.ensure([], () => r(require('@/pages/demo/querytab')), 'querytab')
const querytabbottom = r => require.ensure([], () => r(require('@/pages/demo/querytabbottom')), 'querytabbottom')
const mapdemo = r => require.ensure([], () => r(require('@/pages/demo/mapdemo')), 'mapdemo')
const ScrollBar = r => require.ensure([], () => r(require('@/pages/demo/ScrollBar')), 'ScrollBar')
const H5Upload = r => require.ensure([], () => r(require('@/pages/demo/H5Upload')), 'H5Upload')
// demo end
// testlc

// 蔚蓝·游
const blueindex = r => require.ensure([], () => r(require('@/pages/bluetravel/blueindex')), 'blueindex')
// 蔚蓝游二级页面
const bluetwo = r => require.ensure([], () => r(require('@/pages/bluetravel/blue_two')), 'blue_two')
// 蔚蓝游场所列表
const placelist = r => require.ensure([], () => r(require('@/pages/bluetravel/placelist')), 'placelist')
// 推荐详情页面
const recommenddetail = r => require.ensure([], () => r(require('@/pages/bluetravel/recommend_detail')), 'recommend_detail')
// 在线预订
const bookonline = r => require.ensure([], () => r(require('@/pages/bluetravel/bookonline')), 'bookonline')
// 枫红食一级列表
const redlist = r => require.ensure([], () => r(require('@/pages/redgoods/redlist')), 'redlist')
// 枫红食场所列表
const redplacelist = r => require.ensure([], () => r(require('@/pages/redgoods/redplacelist')), 'redplacelist')
// 枫红食二级列表
const redtypelist = r => require.ensure([], () => r(require('@/pages/redgoods/redtypelist')), 'redtypelist')
// 枫红食详情
const redinfo = r => require.ensure([], () => r(require('@/pages/redgoods/redinfo')), 'redinfo')
// 爱评不评页面
const lovepingnoping = r => require.ensure([], () => r(require('@/pages/bluetravel/lovepingnoping')), 'lovepingnoping')
// 评论详情页面
const speakdetail = r => require.ensure([], () => r(require('@/pages/bluetravel/speak_detail')), 'speak_detail')
// 地图轮播页面
const carouselmap = r => require.ensure([], () => r(require('@/pages/bluetravel/carouselmap')), 'carouselmap')
const trafficIndex = r => require.ensure([], () => r(require('@/pages/traffic/trafficIndex')), 'trafficIndex')
const rentList = r => require.ensure([], () => r(require('@/pages/traffic/rentList')), 'rentList')
const rentComInfo = r => require.ensure([], () => r(require('@/pages/traffic/rentComInfo')), 'rentComInfo')
const liveindex = r => require.ensure([], () => r(require('@/pages/goldenlive/liveindex')), 'liveindex')
const livetypelist = r => require.ensure([], () => r(require('@/pages/goldenlive/livetypelist')), 'livetypelist')
const livelist = r => require.ensure([], () => r(require('@/pages/goldenlive/livelist')), 'livelist')
const liveinfo = r => require.ensure([], () => r(require('@/pages/goldenlive/liveinfo')), 'liveinfo')
// 灵紫购一级列表
const buylist = r => require.ensure([], () => r(require('@/pages/purplebuy/buylist')), 'buylist')
// 灵紫购场所列表
const buyplacelist = r => require.ensure([], () => r(require('@/pages/purplebuy/buyplacelist')), 'buyplacelist')
// 灵紫购详情
const buyinfo = r => require.ensure([], () => r(require('@/pages/purplebuy/buyinfo')), 'buyinfo')
// 灵紫购二级列表
const buytypelist = r => require.ensure([], () => r(require('@/pages/purplebuy/buytypelist')), 'buytypelist')
// 热门游记列表
const travelnoteslist = r => require.ensure([], () => r(require('@/pages/travelnotes/travelnoteslist')), 'travelnoteslist')
// 热门游记详情
const travelnotesinfo = r => require.ensure([], () => r(require('@/pages/travelnotes/travelnotesinfo')), 'travelnotesinfo')
// 日历
const boutiquecalendar = r => require.ensure([], () => r(require('@/pages/boutiqueline/boutiquecalendar')), 'boutiquecalendar')
// 精品线路
const boutiquelineindex = r => require.ensure([], () => r(require('@/pages/boutiqueline/boutiquelineindex')), 'boutiquelineindex')
// 精品线路详情
const boutiquelinedetail = r => require.ensure([], () => r(require('@/pages/boutiqueline/boutiquelinedetail')), 'boutiquelinedetail')
// 日历demo
const rili = r => require.ensure([], () => r(require('@/pages/travelnotes/rili')), 'rili')
// 酒店下单
const liveorder = r => require.ensure([], () => r(require('@/pages/goldenlive/liveorder')), 'liveorder')
// 酒店在线预定
const onlinebooking = r => require.ensure([], () => r(require('@/pages/goldenlive/online_booking')), 'online_booking')
// 精品线路详情
const boutiquelineinfo = r => require.ensure([], () => r(require('@/pages/boutiqueline/boutiquelineinfo')), 'boutiquelineinfo')
// 精品线路预订
const boutiquelinebuy = r => require.ensure([], () => r(require('@/pages/boutiqueline/boutiquelinebuy')), 'boutiquelinebuy')
// 精品线路预定步骤
const boutiquelinestep1 = r => require.ensure([], () => r(require('@/pages/boutiqueline/boutiquelinestep1')), 'boutiquelinestep1')
// 精品线路选择用户信息
const myFriend = r => require.ensure([], () => r(require('@/pages/boutiqueline/myFriend')), 'myFriend')
// 精品线路编辑用户boutique_adduser
const boutiqueadduser = r => require.ensure([], () => r(require('@/pages/boutiqueline/boutique_adduser')), 'boutique_adduser')
// 票在线预定
const blueonlinebooking = r => require.ensure([], () => r(require('@/pages/bluetravel/blue_onlinebooking')), 'blue_onlinebooking')
// 蔚蓝游提交订单
const blueordersubmit = r => require.ensure([], () => r(require('@/pages/bluetravel/blue_ordersubmit')), 'blue_ordersubmit')
// 酒店筛选
const hotelSelection = r => require.ensure([], () => r(require('@/pages/goldenlive/hotelSelection')), 'hotelSelection')
// 个人中心首页
const centerindex = r => require.ensure([], () => r(require('@/pages/personalcenter/centerindex')), 'centerindex')
// 我的攻略
const myraiders = r => require.ensure([], () => r(require('@/pages/personalcenter/myraiders')), 'myraiders')
// 实名认证
const memberreg = r => require.ensure([], () => r(require('@/pages/bluetravel/member_reg')), 'member_reg')
// 我的收藏
const myCollection = r => require.ensure([], () => r(require('@/pages/personalcenter/myCollection')), 'myCollection')
// 我的足迹
const myFootprint = r => require.ensure([], () => r(require('@/pages/personalcenter/myFootprint')), 'myFootprint')
// 我的投诉
const myComplaint = r => require.ensure([], () => r(require('@/pages/personalcenter/myComplaint')), 'myComplaint')
// 添加投诉
const addComplaint = r => require.ensure([], () => r(require('@/pages/personalcenter/addComplaint')), 'addComplaint')
// 好友列表
const boutiquelinefriend = r => require.ensure([], () => r(require('@/pages/boutiqueline/boutiqueline_friend')), 'boutiqueline_friend')
// 投诉详情
const complaintInfo = r => require.ensure([], () => r(require('@/pages/personalcenter/complaintInfo')), 'complaintInfo')
// 支付成功页面order_success_line
const ordersuccessline = r => require.ensure([], () => r(require('@/pages/boutiqueline/order_success_line')), 'order_success_line')
// 我的评论
const myComment = r => require.ensure([], () => r(require('@/pages/personalcenter/myComment')), 'myComment')
// 线路支付页面
const boutiquepay = r => require.ensure([], () => r(require('@/pages/boutiqueline/boutique_pay')), 'boutique_pay')
// 精品线路订单详情
const boutiquelineorderinfo = r => require.ensure([], () => r(require('@/pages/boutiqueline/boutiqueline_order_info')), 'boutiqueline_order_info')
// 我的订单
const myOrderList = r => require.ensure([], () => r(require('@/pages/personalcenter/myOrderList')), 'myOrderList')
// 首页
const appIndex = r => require.ensure([], () => r(require('@/pages/login/appIndex')), 'appIndex')
// 添加游记
const addnotes = r => require.ensure([], () => r(require('@/pages/travelnotes/addnotes')), 'addnotes')
// 我的游记列表
const myNotesList = r => require.ensure([], () => r(require('@/pages/personalcenter/myNotesList')), 'myNotesList')
let router = new Router({
  routes: [
    {
      path: '/myNotesList',
      name: '我的游记',
      component: myNotesList
    },
    {
      path: '/addnotes',
      name: '添加游记',
      component: addnotes
    },
    {
      path: '/appIndex',
      name: '首页',
      component: appIndex
    },
    {
      path: '/myOrderList',
      name: '我的订单',
      component: myOrderList
    },
    {
      path: '/myComment',
      name: '我的评论',
      component: myComment
    },
    {
      path: '/addComplaint',
      name: '添加投诉',
      meta: {
        title: '添加投诉'
      },
      component: addComplaint
    },
    {
      path: '/complaintInfo',
      name: '投诉详情',
      component: complaintInfo
    },
    {
      path: '/myCollection',
      name: '我的收藏',
      component: myCollection
    },
    {
      path: '/myFootprint',
      name: '我的足迹',
      component: myFootprint
    },
    {
      path: '/myComplaint',
      name: '我的投诉',
      component: myComplaint
    },
    {
      path: '/hotelSelection',
      name: 'hotelSelection',
      component: hotelSelection
    },
    {
      path: '/member_reg',
      name: 'member_reg',
      component: memberreg
    },
    {
      path: '/myraiders',
      name: '我的攻略',
      component: myraiders
    },
    {
      path: '/centerindex',
      name: '个人中心',
      component: centerindex
    },
    {
      path: '/blue_ordersubmit',
      name: '订单提交',
      component: blueordersubmit
    },
    {
      path: '/blue_onlinebooking',
      name: '在线预定',
      component: blueonlinebooking
    },
    {
      path: '/liveorder',
      name: '酒店下单',
      component: liveorder
    },
    {
      path: '/online_booking',
      name: '在线预定',
      component: onlinebooking

    },
    {
      path: '/boutiquelinedetail',
      name: '线路详情',
      component: boutiquelinedetail
    },
    {
      path: '/boutiquelineindex',
      name: '精品线路',
      component: boutiquelineindex
    },
    {
      path: '/boutiquecalendar',
      name: 'boutiquecalendar',
      component: boutiquecalendar
    },
    {
      path: '/boutiquelineinfo',
      name: '线路详情',
      component: boutiquelineinfo
    },
    {
      path: '/boutiquelinebuy',
      name: '线路预定',
      component: boutiquelinebuy
    },
    {
      path: '/boutiquelinestep1',
      name: '线路预定',
      component: boutiquelinestep1
    },
    {
      path: '/myFriend',
      name: 'myFriend',
      component: myFriend
    },
    {
      path: '/boutique_adduser',
      name: 'boutique_adduser',
      component: boutiqueadduser
    },
    {
      path: '/boutiqueline_friend',
      name: 'boutiqueline_friend',
      component: boutiquelinefriend
    },
    {
      path: '/order_success_line',
      name: 'order_success_line',
      component: ordersuccessline
    },
    {
      path: '/boutique_pay',
      name: '支付',
      component: boutiquepay
    },
    {
      path: '/boutiqueline_order_info',
      name: 'boutiqueline_order_info',
      component: boutiquelineorderinfo
    },
    {
      path: '/rili',
      name: 'rili',
      component: rili
    },
    {
      path: '/travelnotesinfo',
      name: '游记详情',
      component: travelnotesinfo
    },
    {
      path: '/travelnoteslist',
      name: '热门游记',
      component: travelnoteslist
    },
    {
      path: '/buytypelist',
      name: 'buytypelist',
      component: buytypelist
    },
    {
      path: '/buyinfo',
      name: 'buyinfo',
      component: buyinfo
    },
    {
      path: '/buyplacelist',
      name: 'buyplacelist',
      component: buyplacelist
    },
    {
      path: '/buylist',
      name: '购',
      component: buylist
    },
    {
      path: '/rentComInfo',
      name: 'rentComInfo',
      component: rentComInfo
    },
    {
      path: '/rentList',
      name: '行',
      component: rentList
    },
    {
      path: '/trafficIndex',
      name: '行',
      component: trafficIndex
    },
    {
      path: '/liveindex',
      name: '住',
      component: liveindex
    },
    {
      path: '/liveinfo',
      name: 'liveinfo',
      component: liveinfo
    },
    {
      path: '/livelist',
      name: 'livelist',
      component: livelist
    },
    {
      path: '/livetypelist',
      name: 'livetypelist',
      component: livetypelist
    },
    {
      path: '/redinfo',
      name: 'redinfo',
      component: redinfo
    },
    {
      path: '/redplacelist',
      name: 'redplacelist',
      component: redplacelist
    },
    {
      path: '/',
      name: 'HomeIndex',
      component: HomeIndex
    },
    {
      path: '/demo',
      name: 'demo',
      component: demo
    },
    {
      path: '/demo/ScrollBar',
      name: 'ScrollBar',
      component: ScrollBar
    },
    {
      path: '/demo/H5Upload',
      name: 'H5Upload',
      component: H5Upload
    },
    {
      path: '/demo/querytab',
      name: 'querytab',
      component: querytab
    },
    {
      path: '/demo/querytabbottom',
      name: 'querytabbottom',
      component: querytabbottom
    },
    {
      path: '/demo/mapdemo',
      name: 'mapdemo',
      component: mapdemo
    },
    {
      path: '/redtypelist', // 热门盘点
      name: 'redtypelist',
      component: redtypelist
    },
    {
      path: '/MyInfo', // url 路由地址
      name: 'MyInfo',
      component: MyInfo
    },
    {
      path: '/My', // url 我的主页
      name: 'My',
      component: My
    },
    {
      path: '/UserInfo', // url 用户信息
      name: 'UserInfo',
      component: UserInfo
    },
    {
      path: '/Updatepswd', // url 修改密码
      name: 'Updatepswd',
      component: Updatepswd
    },
    {
      path: '/UpdatePhoneNum', // url 改绑手机
      name: 'UpdatePhoneNum',
      component: UpdatePhoneNum
    },
    {
      path: '/redlist', // 枫叶·食index
      name: '食',
      component: redlist
    },
    {
      path: '/blueindex', // 蔚蓝·游index
      name: '游',
      component: blueindex
    },
    {
      path: '/blue_two', // 蔚蓝·游二级列表
      name: 'blue_two',
      component: bluetwo
    },
    {
      path: '/placelist', // 蔚蓝·游二级列表
      name: 'placelist',
      component: placelist
    },
    {
      path: '/recommend_detail', // 蔚蓝·游推荐详情页面
      name: 'recommend_detail',
      component: recommenddetail
    },
    {
      path: '/bookonline', // 蔚蓝·游推荐详情页面
      name: 'bookonline',
      component: bookonline
    },
    {
      path: '/lovepingnoping', // 爱评不评页面
      name: '爱评不评',
      component: lovepingnoping
    },
    {
      path: '/carouselmap', // 地图轮播页面
      name: 'carouselmap',
      component: carouselmap
    },
    {
      path: '/speak_detail', // 评论详情页面
      name: '评论详情',
      component: speakdetail
    },
    {
      path: '/MyCard', // url 改绑手机
      name: 'MyCard',
      component: MyCard
    },
    {
      path: '/Home', // url 路由地址
      name: 'Home',
      component: Home,
      children: [
        {
          path: 'MyInfo', // 子路由,我的页面
          component: MyInfo,
          meta: { requiresAuth: true } // 是否需要登录验证
        },
        {
          path: 'form', // 子路由,我的页面
          component: form,
          name: '我的表单',
          meta: {
            header: false
          }
        }
      ]
    },
    {
      path: '/Login', // 登录路由
      name: 'Login',
      component: Login
    },
    {
      path: '/appLogin', // 登录路由
      name: '实名认证',
      component: appLogin
    },
    {
      path: '/Register', // 登录注册路由
      name: '注册/登陆',
      component: Register,
      meta: {
        title: '登录' // 配置 页面 title 信息
      },
      children: [
        {
          path: 'Retrievepassword', // 子路由,找回密码
          component: Retrievepassword
        }
      ]
    },
    {
      path: '/Retrievepassword', // 登录路由
      name: '找回密码',
      component: Retrievepassword
    }
  ]
})

router.beforeEach((to, from, next) => {
  /* 显示加载中动画 */
  store.commit(PAGELOADING, true)
  if (to.matched.some(record => record.meta.requiresAuth)) {
    // this route requires auth, check if logged in
    // if not, redirect to login page.
    if (!storejs.get(STORECONST.USERINFO)) {
      next({
        path: '/Login',
        query: { redirect: to.fullPath }
      })
    } else {
      next()
    }
  } else {
    next() // 确保一定要调用 next()
  }
})

router.afterEach(route => {
  /* 隐藏加载中动画 */
  store.commit(PAGELOADING, false)
  // 修改 title 信息,兼容微信头部信息
  if (route.meta.title) {
    document.title = route.meta.title
    let ua = navigator.userAgent
    if (/\bMicroMessenger\/([\d.]+)/.test(ua) && /ip(hone|od|ad)/i.test(ua)) {
      var i = document.createElement('iframe')
      i.src = '/favicon.ico'
      i.style.display = 'none'
      i.onload = function () {
        setTimeout(function () {
          i.remove()
        }, 9)
      }
      document.body.appendChild(i)
    }
  }
})

Vue.use(Router)

export default router
